package com.lin.mock.pay.server.service.impl;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.lin.mock.pay.server.model.dto.OrderTaskDTO;
import com.lin.mock.pay.server.model.vo.CloseOrderVO;
import com.lin.mock.pay.server.model.vo.PrepayOrderVO;
import com.lin.mock.pay.server.model.vo.QueryOrderVO;
import com.lin.mock.pay.server.model.vo.RefundsOrderVO;
import com.lin.mock.pay.server.service.MockPayService;
import com.lin.mock.pay.server.task.TaskManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: linjiang
 * @date: 2024/12/13
 */
@Slf4j
@Service
public class MockServiceImpl implements MockPayService {
    @Autowired
    private TaskManager manager;

    @Override
    public JSONObject prepay(PrepayOrderVO body) {
        log.info("接收到的支付参数：{}", JSON.toJSONString(body));
        JSONObject respParams = new JSONObject();
        respParams.put("returnCode", "0");
        respParams.put("returnMsg", "成功");
        respParams.put("wx_data_package", "小程序支付数据包");

        // 投递任务
        OrderTaskDTO task = OrderTaskDTO.builder().attach(body.getAttach()).outTradeNo(body.getOutTradeNo())
                .notifyUrl(body.getNotifyUrl()).build();
        manager.add(task);
        return respParams;
    }

    @Override
    public void close(CloseOrderVO body) {
        log.info("接收到的关单参数：{}", JSON.toJSONString(body));
    }

    @Override
    public void query(QueryOrderVO body) {
        log.info("接收到的查单参数：{}", JSON.toJSONString(body));
    }

    @Override
    public void refund(RefundsOrderVO body) {
        log.info("接收到的退单参数：{}", JSON.toJSONString(body));
    }

}
